import {CHANGE_INPUT_VALUE,ADD_ITEM,DELETE_ITEM,Init_DATA_LIST} from './ActionTypes'
const defaultState = {
    inputValue:'123',
    list:['Racing car sprays burning fuel into crowd.',
    'Japanese princess to wed commoner.',
    'Australian walks 100km after outback crash.',
    'Man charged over missing wedding girl.',
    'Los Angeles battles huge wildfires.'],
};
export default (state = defaultState,action)=>{
    if(action.type == CHANGE_INPUT_VALUE){
        var newState = JSON.parse(JSON.stringify(state));
        newState.inputValue = action.value;
        return newState;
    }
    if(action.type == ADD_ITEM){
        var newState = JSON.parse(JSON.stringify(state));
        newState.list.push(newState.inputValue);
        newState.inputValue = '';
        return newState;
    }
    if(action.type == DELETE_ITEM){
        var newState = JSON.parse(JSON.stringify(state));
        newState.list.splice(action.index,1);
        return newState;
    }
    if(action.type == Init_DATA_LIST){
        var newState = JSON.parse(JSON.stringify(state));
        newState.list = action.data;
        return newState;
    }
    //console.log(state,action);
    return state;
}